package com.geostar.constructionland.attachment.entity;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import com.mongodb.client.gridfs.model.GridFSFile;
import org.apache.commons.beanutils.BeanUtils;

import com.mongodb.gridfs.GridFSDBFile;

//确认必须写GeoFile.files
//@Document(collection = "GeoFile.files")
public class FileObject implements Serializable {
    
    private static final long serialVersionUID = 7460833048204683980L;
    
    //mongo中的_id
//    @Id
    private String id;
    //系统来源唯一标识ID
    private String indentifyId;
    //文件唯一ID
    private String fileId;
    //用户ID
    private String userId;
    //分类ID
    private String folderId;
    //分类名称
    private String folderName;
    //原文件名称
    private String fileName;
    //创建时间   yyyy-MM-dd HH:mm:ss
    private String creationTime;
    //最后修改时间  yyyy-MM-dd HH:mm:ss 
    private String lastModifyTime;
    //是否删除    0:否；1:已删除
    private String isDeleted = "0";
    //文件共享  0:不共享状态   1:共享状态
    private String isShare;
    //文件大小
    private Long size;
    //数据源id
    private String sourceId;
    //数据源对象路径
    private String path;
    //yes表示该文件要进行OCR文字识别处理
    //no 表示不进行
    private String doOCR;
    //OCR文字识别结果
    private String textContent;
    //标记字段用来实现事务控制
    private String status;
    
    public FileObject() {
        
    }
    
    public String getPath() {
        return path;
    }
    
    public void setPath(String path) {
        this.path = path;
    }
    
    public String getId() {
        return id;
    }
    
    public void setId(String id) {
        this.id = id;
    }
    
    public String getFileId() {
        return fileId;
    }
    
    public void setFileId(String fileId) {
        this.fileId = fileId;
    }
    
    public String getIndentifyId() {
        return indentifyId;
    }
    
    public void setIndentifyId(String indentifyId) {
        this.indentifyId = indentifyId;
    }
    
    public String getUserId() {
        return userId;
    }
    
    public void setUserId(String userId) {
        this.userId = userId;
    }
    
    public String getFolderId() {
        return folderId;
    }
    
    public void setFolderId(String folderId) {
        this.folderId = folderId;
    }
    
    public String getFileName() {
        return fileName;
    }
    
    public void setFileName(String fileName) {
        this.fileName = fileName;
    }
    
    public Long getSize() {
        return size;
    }
    
    public void setSize(Long size) {
        this.size = size;
    }
    
    public String getFolderName() {
        return folderName;
    }
    
    public void setFolderName(String folderName) {
        this.folderName = folderName;
    }
    
    public String getCreationTime() {
        return creationTime;
    }
    
    public void setCreationTime(String creationTime) {
        this.creationTime = creationTime;
    }
    
    public String getLastModifyTime() {
        return lastModifyTime;
    }
    
    public void setLastModifyTime(String lastModifyTime) {
        this.lastModifyTime = lastModifyTime;
    }
    
    public String getIsDeleted() {
        return isDeleted;
    }
    
    public void setIsDeleted(String isDeleted) {
        this.isDeleted = isDeleted;
    }
    
    public String getSourceId() {
        return sourceId;
    }
    
    public void setSourceId(String sourceId) {
        this.sourceId = sourceId;
    }
    
    public String getIsShare() {
        return isShare;
    }
    
    public void setIsShare(String isShare) {
        this.isShare = isShare;
    }
    
    public String getTextContent() {
        return textContent;
    }
    
    public void setTextContent(String textContent) {
        this.textContent = textContent;
    }
    
    public String getDoOCR() {
        return doOCR;
    }
    
    public void setDoOCR(String doOCR) {
        this.doOCR = doOCR;
    }
    
    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public static FileObject fromGridFSDBFile(GridFSDBFile gridFSDBFile) throws IllegalAccessException, InvocationTargetException {
        FileObject fileObject = null;
        if (gridFSDBFile != null) {
            fileObject = new FileObject();
            Field[] fields = fileObject.getClass().getDeclaredFields();
            Map<String, Object> map = new HashMap<>(fields.length);
            for (int i = 0; i < fields.length; i++) {
                String key = fields[i].getName();
                map.put(key, gridFSDBFile.get(key));
            }
            BeanUtils.populate(fileObject, map);
        }
        return fileObject;
    }

    @Override
    public String toString() {
        return "FileObject [id=" + id + ", indentifyId=" + indentifyId + ", fileId=" + fileId + ", userId=" + userId + ", folderId=" + folderId + ", folderName=" + folderName + ", fileName="
                + fileName + ", creationTime=" + creationTime + ", lastModifyTime=" + lastModifyTime + ", isDeleted=" + isDeleted + ", isShare=" + isShare + ", size=" + size + ", sourceId=" + sourceId
                + ", path=" + path + ", doOCR=" + doOCR + ", textContent=" + textContent + ", status=" + status + "]";
    }
    
}
